<?php
define('PHP5_PHP', true);

global $php5DB,$php5Config, $php5Template, $php5User, $php5Session, $php5TemplatePath, $php5Msg, $php5Section, $language, $task, $define;
global $msgAlert, $redirect, $php5DB;
include("configs/extension.inc");
include("configs/config".$php5Ext);

$language = 'en';


/*if(!is_file($php5RootPath . "/includes/php5_common" . $php5Ext)){
	echo "To check the config file.";
	die();
}

require_once($php5RootPath . "/includes/php5_define" . $php5Ext);
require_once($php5RootPath . "/includes/class.inputfilter" . $php5Ext);
require_once($php5RootPath . "/includes/php5_common" . $php5Ext);

//End get params
// start init
php5Init( 0 );*/
function smtpcom_get( $ch, $url ) {
	curl_setopt($ch, CURLOPT_URL, $url);
	$res = curl_exec($ch);
	if ( !curl_errno($ch) && $res ) {
		$parsed = json_decode($res, 1);
		if ( !$parsed['code'] ){
			return $parsed;
		} else {
			//echo 'Error ' . @$parse['code'] . '.' . @$parse['message'];
		}
	} else {
		echo 'Some error was occured: ' . curl_errno($ch);
	}
}
$time_start = date('01-m-Y', time());
$time_end = date('d-m-Y', time());
if(isset($_POST['task'])) {
	$time_start      = $_POST['from_date'];
	$time_end = $_POST['to_date'];
}

$api_url = 'https://api.smtp.com/v1/';
$key     = 'e23e6678e0d32f25d5a29c344b505250ae15fd3e'; #your_key

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$senders_url = $api_url . '/account/senders.json?api_key=' . $key;
$res = smtpcom_get( $ch, $senders_url );
$senders = $res['senders'];
$summary = '';
if(is_array($senders) && count($senders) > 0) {
	foreach($senders as $k => $arr){
		if($arr['login'] == php5GetConfig('config_smtp_username')) {
			$sender = $senders[$k];
			$date1 = '';
			$date2 = '';
			if($time_start) {
				$date1 = "00:00%20{$time_start}";
			}
			if($time_end) {
				$date2 = "23:59%20{$time_end}";
			}	
			$summary_url = $api_url. '/account/senders/' . $sender['label'] . '/statistics/delivery.json?api_key=' . $key . '&time_start="'.$date1.'"&time_end="'.$date2.'"&limit=10000&offset=0';
		
			$res = smtpcom_get( $ch, $summary_url );
			$summary = $res['delivery'];
			if(count($summary) > 0) {
				print_r($summary);	
				
			}			
			break;
		}
	}
}
	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html slick-uniqueid="3" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" dir="ltr" lang="en-gb"><!-- Footer --><head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <meta name="generator" content="Humming! - Shopping cart">
  <title>DMA - Administration</title>
  <script src="index_files/global.js" type="text/javascript"></script>
  <script src="index_files/jquery.js" type="text/javascript"></script>
  <script src="index_files/mootools-core.js" type="text/javascript"></script>
  <script src="index_files/core.js" type="text/javascript"></script>
  <script src="index_files/mootools-more.js" type="text/javascript"></script>
<!-- Load system style CSS -->
<link rel="stylesheet" href="index_files/system.css" type="text/css">

<!-- Load Template CSS -->
<link href="index_files/template.css" rel="stylesheet" type="text/css">

<!-- Load additional CSS styles for colors -->
<link href="index_files/colour_standard.css" rel="stylesheet" type="text/css">

<!-- Load additional CSS styles for rtl sites -->

<!-- Load specific language related css -->

<!-- Load additional CSS styles for bold Text -->

<!-- Load additional CSS styles for Internet Explorer -->
<!--[if IE 8]>
	<link href="insite/templates/hathor/css/ie8.css" rel="stylesheet" type="text/css" />
<![endif]-->
<!--[if IE 7]>
	<link href="insite/templates/hathor/css/ie7.css" rel="stylesheet" type="text/css" />
<![endif]-->
<!--[if lte IE 6]>
	<link href="insite/templates/hathor/css/ie6.css" rel="stylesheet" type="text/css" />
<![endif]-->

<!-- Load Template JavaScript -->
<script type="text/javascript" src="index_files/template.js"></script>

<link href="index_files/style.css" rel="stylesheet" type="text/css">
<link href="index_files/forms.css" rel="stylesheet" type="text/css">
<link href="index_files/tooltip.htm" rel="stylesheet" type="text/css">

<script src="index_files/ajaxfileupload.js" type="text/javascript"></script>
<script src="index_files/CalendarPopup.js" type="text/javascript"></script>

<script>
var cal = new CalendarPopup();
</script>

</head>
<body id="minwidth-body">
<div id="containerwrap"> 
  <!-- Header Logo -->
  <div role="banner" id="header"> 
    
    <!-- Site Title and Skip to Content -->
    <div class="title-ua">
      <h1 class="title">Administration</h1>
      <div id="skiplinkholder">
        <p><a id="skiplink" href="#skiptarget">Skip to Main Content</a></p>
      </div>
    </div>
  </div>
  <!-- end header --> 
  
  <!-- Main Menu Navigation -->
  <div role="navigation" id="nav">
    <div id="module-menu">
		<h2 class="element-invisible">Main Menu</h2>
<ul id="menu">
  <li class="node"> <a href="#">Site</a>
    <ul>
      <li class="separator"><span></span></li>
      <li><a class="icon-16-config" href="#">Global Configuration</a></li>
      <li class="separator"><span></span></li>
      <li><a class="icon-16-logout" href="#">Logout</a></li>
    </ul>
  </li>
</ul>
</div>
    <div class="clr"></div>
  </div>
  <!-- end nav --> 
  
  <!-- Status Module -->
  <div id="module-status"> <span class="loggedin-users">0 Visitors</span><span class="backloggedin-users">1 Admin</span><span class="no-unread-messages"><a href="#">0</a></span> <span class="viewsite"><a href="#" target="_blank">View Site</a></span><span class="logout"><a href="#">Log out</a></span> </div>
  <!-- main --> 
  <div id="content">

		<!-- Component Title -->
			<div class="pagetitle icon-48-cpanel"><h2>Control Panel</h2></div>

		<!-- System Messages -->
		
<div id="system-message-container">
</div>
		<!-- Sub Menu Navigation -->
		<div id="no-submenu"></div>
   		<div class="clr"></div>

		<!-- Beginning of Actual Content -->
		<div role="main" id="element-box">
			<p id="skiptargetholder"><a id="skiptarget" class="skip" tabindex="-1"></a></p>

				<div class="adminform">

					<!-- Display the Quick Icon Shortcuts -->
					<div class="cpanel-icons">
						<div class="cpanel"><div class="icon-wrapper">
							<style>
              table.summaryTable
              {
                width: 554px;
              }
              table.summaryTable tr
              {
                height: 30px;
              }
              </style>
<form method="post" name="frmAdmin">
              <table cellspacing="5" cellpadding="5" align="center" border="1">
                  <tbody>
                  <tr>
                      <td colspan="4"><h3>Filter:</h3></td>
                  </tr>
                  <tr>
                      <td ><b>From Date</b>:&nbsp;<input type="text" value="<?=$time_start?>" name="from_date"  style="width:100px" class="required"  />&nbsp;<img src="index_files/cal.gif" NAME="anchor2" align="absmiddle" ID="anchor2"  onclick="cal.select(document.forms['frmAdmin'].from_date,'anchor2','dd-MM-yyyy'); return false;" />&nbsp;</td>
                      <td ><b>To Date</b>::&nbsp;<input type="text" value="<?=$time_end?>" name="to_date"  style="width:100px" class="required"  />&nbsp;<img src="index_files/cal.gif" NAME="anchor1" align="absmiddle" ID="anchor1"  onclick="cal.select(document.forms['frmAdmin'].to_date,'anchor1','dd-MM-yyyy'); return false;" />&nbsp;</td>
					<td><input type="submit" value="search" /></td>
                  </tr>
              </tbody></table>
              
              <table cellspacing="5" cellpadding="5" align="center" border="1">
                  <tbody>
                  <tr>
                      <td colspan="4"><h3>Manage emails:</h3></td>
                  </tr>
                  <tr>
                      <td width="35%"><b>Date</b></td>
                      <td width="35%"><b>From</b></td>
                      <td width="15%"><b>Status(1:sent;3:bouced)</b></td>
                      <td width="15%"><b>To</b></td>
                  </tr>
               <?
							 foreach($summary  as $row) {
								 ?>
                   <tr>
                      <td width="25%"><?=date('d-m-Y h:i',$row['time_finished'])?></td>
                      <td width="25%"><?=$row['mail_from']?></td>
                      <td width="25%"><?=$row['status']?></td>
                      <td width="25%"><?=$row['rcpt_to']?></td>
                  </tr>                
                 <?
							 }
							 ?>
              </tbody></table>
                 <input type="hidden" name="task" value="search" />
</form>                         
            </div></div>

					</div>

					<!-- Display Admin Information Panels -->

				</div>
				<div class="clr"></div>

		</div><!-- end element-box -->

		<noscript>
			Warning! JavaScript must be enabled for proper operation of the Administrator backend.		</noscript>
		<div class="clr"></div>

	</div><!-- end content -->
  <div class="clr"></div>
</div>
<!-- end containerwrap --> 

<!-- Footer --> 
<div role="contentinfo" id="footer">
  <p align="center">DMA</p>
  <p class="copyright">
        </p>
</div>

</body></html>